﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using shopxachtayphap;

namespace shopxachtayphap
{
    public partial class Products : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string nsx = Request.QueryString["product"];
                string category = Request.QueryString["category"];
                LoadNsx(nsx, category);
                LoadMenu(category);
                LoadProduct(category, nsx);
            }
        }

        private void LoadProduct(string category,string nsx)
        {
            using(var shop = new WebxachtayEntities())
            {
                int nsxId ;
                bool check = int.TryParse(nsx, out nsxId);
                var products = !check ? shop.Products.Where(x => category.Contains(x.CategoryId)).ToList() : shop.Products.Where(x => category.Contains(x.CategoryId) && x.ManufactureId == nsxId).ToList();

                rptTab1.DataSource = products;
                rptTab1.DataBind();
                rptTab2.DataSource = products;
                rptTab2.DataBind();
            }
        }
        private void LoadMenu(string category)
        {
            string list = Untils.LoadCategory(category);
            ltrCategory.Text = list;
        }
        private void LoadNsx(string active,string category)
        {

            string list = Untils.LoadNsx(active, category);
            Literal1.Text = list;
        }
    }
}